home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume13 / rpc3.9 / part08 < prev    next >
Encoding:
Internet Message Format  |  1988-02-27  |  53.6 KB

  1. Subject:  v13i085:  Sun RPC, release 3.9, Part08/15
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Stephen X. Nahm <sxn@Sun.COM>
  7. Posting-number: Volume 13, Issue 85
  8. Archive-name: rpc3.9/part08
  9.  
  10. #! /bin/sh
  11. # This is a shell archive. To extract, remove the header and type "sh filename"
  12. #
  13. cd rpcgen
  14. echo x - rpc_svcout.c
  15. cat > rpc_svcout.c <<'Funky_Stuff'
  16. /* @(#)rpc_svcout.c    1.2 87/11/24 3.9 RPCSRC */
  17. /*
  18.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  19.  * unrestricted use provided that this legend is included on all tape
  20.  * media and as a part of the software program in whole or part.  Users
  21.  * may copy or modify Sun RPC without charge, but are not authorized
  22.  * to license or distribute it to anyone else except as part of a product or
  23.  * program developed by the user.
  24.  * 
  25.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  26.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  27.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  28.  * 
  29.  * Sun RPC is provided with no support and without any obligation on the
  30.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  31.  * modification or enhancement.
  32.  * 
  33.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  34.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  35.  * OR ANY PART THEREOF.
  36.  * 
  37.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  38.  * or profits or other special, indirect and consequential damages, even if
  39.  * Sun has been advised of the possibility of such damages.
  40.  * 
  41.  * Sun Microsystems, Inc.
  42.  * 2550 Garcia Avenue
  43.  * Mountain View, California  94043
  44.  */
  45. #ifndef lint
  46. static char sccsid[] = "@(#)rpc_svcout.c 1.6 87/06/24 (C) 1987 SMI";
  47. #endif
  48.  
  49. /*
  50.  * rpc_svcout.c, Server-skeleton outputter for the RPC protocol compiler
  51.  * Copyright (C) 1987, Sun Microsytsems, Inc. 
  52.  */
  53. #include <stdio.h>
  54. #include <strings.h>
  55. #include "rpc_parse.h"
  56. #include "rpc_util.h"
  57.  
  58. static char RQSTP[] = "rqstp";
  59. static char TRANSP[] = "transp";
  60. static char ARG[] = "argument";
  61. static char RESULT[] = "result";
  62. static char ROUTINE[] = "local";
  63.  
  64.  
  65. /*
  66.  * write most of the service, that is, everything but the registrations. 
  67.  */
  68. void
  69. write_most()
  70. {
  71.     list *l;
  72.     definition *def;
  73.     version_list *vp;
  74.  
  75.     for (l = defined; l != NULL; l = l->next) {
  76.         def = (definition *) l->val;
  77.         if (def->def_kind == DEF_PROGRAM) {
  78.             for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
  79.                 f_print(fout, "\nstatic void ");
  80.                 pvname(def->def_name, vp->vers_num);
  81.                 f_print(fout, "();");
  82.             }
  83.         }
  84.     }
  85.     f_print(fout, "\n\n");
  86.     f_print(fout, "main()\n");
  87.     f_print(fout, "{\n");
  88.     f_print(fout, "\tSVCXPRT *%s;\n", TRANSP);
  89.     f_print(fout, "\n");
  90.     for (l = defined; l != NULL; l = l->next) {
  91.         def = (definition *) l->val;
  92.         if (def->def_kind != DEF_PROGRAM) {
  93.             continue;
  94.         }
  95.         for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
  96.             f_print(fout, "\tpmap_unset(%s, %s);\n", def->def_name, vp->vers_name);
  97.         }
  98.     }
  99. }
  100.  
  101.  
  102. /*
  103.  * write a registration for the given transport 
  104.  */
  105. void
  106. write_register(transp)
  107.     char *transp;
  108. {
  109.     list *l;
  110.     definition *def;
  111.     version_list *vp;
  112.  
  113.     f_print(fout, "\n");
  114.     f_print(fout, "\t%s = svc%s_create(RPC_ANYSOCK", TRANSP, transp);
  115.     if (streq(transp, "tcp")) {
  116.         f_print(fout, ", 0, 0");
  117.     }
  118.     f_print(fout, ");\n");
  119.     f_print(fout, "\tif (%s == NULL) {\n", TRANSP);
  120.     f_print(fout, "\t\tfprintf(stderr, \"cannot create %s service.\\n\");\n", transp);
  121.     f_print(fout, "\t\texit(1);\n");
  122.     f_print(fout, "\t}\n");
  123.  
  124.     for (l = defined; l != NULL; l = l->next) {
  125.         def = (definition *) l->val;
  126.         if (def->def_kind != DEF_PROGRAM) {
  127.             continue;
  128.         }
  129.         for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
  130.             f_print(fout,
  131.                 "\tif (!svc_register(%s, %s, %s, ",
  132.                 TRANSP, def->def_name, vp->vers_name);
  133.             pvname(def->def_name, vp->vers_num);
  134.             f_print(fout, ", IPPROTO_%s)) {\n",
  135.                 streq(transp, "udp") ? "UDP" : "TCP");
  136.             f_print(fout,
  137.                 "\t\tfprintf(stderr, \"unable to register (%s, %s, %s).\\n\");\n",
  138.                 def->def_name, vp->vers_name, transp);
  139.             f_print(fout, "\t\texit(1);\n");
  140.             f_print(fout, "\t}\n");
  141.         }
  142.     }
  143. }
  144.  
  145.  
  146. /*
  147.  * write the rest of the service 
  148.  */
  149. void
  150. write_rest()
  151. {
  152.     f_print(fout, "\tsvc_run();\n");
  153.     f_print(fout, "\tfprintf(stderr, \"svc_run returned\\n\");\n");
  154.     f_print(fout, "\texit(1);\n");
  155.     f_print(fout, "}\n");
  156. }
  157.  
  158. void
  159. write_programs(storage)
  160.     char *storage;
  161. {
  162.     list *l;
  163.     definition *def;
  164.  
  165.     for (l = defined; l != NULL; l = l->next) {
  166.         def = (definition *) l->val;
  167.         if (def->def_kind == DEF_PROGRAM) {
  168.             write_program(def, storage);
  169.         }
  170.     }
  171. }
  172.  
  173.  
  174. static
  175. write_program(def, storage)
  176.     definition *def;
  177.     char *storage;
  178. {
  179.     version_list *vp;
  180.     proc_list *proc;
  181.     int filled;
  182.  
  183.     for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
  184.         f_print(fout, "\n");
  185.         if (storage != NULL) {
  186.             f_print(fout, "%s ", storage);
  187.         }
  188.         f_print(fout, "void\n");
  189.         pvname(def->def_name, vp->vers_num);
  190.         f_print(fout, "(%s, %s)\n", RQSTP, TRANSP);
  191.         f_print(fout, "    struct svc_req *%s;\n", RQSTP);
  192.         f_print(fout, "    SVCXPRT *%s;\n", TRANSP);
  193.         f_print(fout, "{\n");
  194.  
  195.         filled = 0;
  196.         f_print(fout, "\tunion {\n");
  197.         for (proc = vp->procs; proc != NULL; proc = proc->next) {
  198.             if (streq(proc->arg_type, "void")) {
  199.                 continue;
  200.             }
  201.             filled = 1;
  202.             f_print(fout, "\t\t");
  203.             ptype(proc->arg_prefix, proc->arg_type, 0);
  204.             pvname(proc->proc_name, vp->vers_num);
  205.             f_print(fout, "_arg;\n");
  206.         }
  207.         if (!filled) {
  208.             f_print(fout, "\t\tint fill;\n");
  209.         }
  210.         f_print(fout, "\t} %s;\n", ARG);
  211.         f_print(fout, "\tchar *%s;\n", RESULT);
  212.         f_print(fout, "\tbool_t (*xdr_%s)(), (*xdr_%s)();\n", ARG, RESULT);
  213.         f_print(fout, "\tchar *(*%s)();\n", ROUTINE);
  214.         f_print(fout, "\n");
  215.         f_print(fout, "\tswitch (%s->rq_proc) {\n", RQSTP);
  216.  
  217.         if (!nullproc(vp->procs)) {
  218.             f_print(fout, "\tcase NULLPROC:\n");
  219.             f_print(fout, "\t\tsvc_sendreply(%s, xdr_void, NULL);\n", TRANSP);
  220.             f_print(fout, "\t\treturn;\n\n");
  221.         }
  222.         for (proc = vp->procs; proc != NULL; proc = proc->next) {
  223.             f_print(fout, "\tcase %s:\n", proc->proc_name);
  224.             f_print(fout, "\t\txdr_%s = xdr_%s;\n", ARG, 
  225.                 stringfix(proc->arg_type));
  226.             f_print(fout, "\t\txdr_%s = xdr_%s;\n", RESULT, 
  227.                 stringfix(proc->res_type));
  228.             f_print(fout, "\t\t%s = (char *(*)()) ", ROUTINE);
  229.             pvname(proc->proc_name, vp->vers_num);
  230.             f_print(fout, ";\n");
  231.             f_print(fout, "\t\tbreak;\n\n");
  232.         }
  233.         f_print(fout, "\tdefault:\n");
  234.         printerr("noproc", TRANSP);
  235.         f_print(fout, "\t\treturn;\n");
  236.         f_print(fout, "\t}\n");
  237.  
  238.         f_print(fout, "\tbzero(&%s, sizeof(%s));\n", ARG, ARG);
  239.         printif("getargs", TRANSP, "&", ARG);
  240.         printerr("decode", TRANSP);
  241.         f_print(fout, "\t\treturn;\n");
  242.         f_print(fout, "\t}\n");
  243.  
  244.         f_print(fout, "\t%s = (*%s)(&%s, %s);\n", RESULT, ROUTINE, ARG,
  245.             RQSTP);
  246.         f_print(fout, 
  247.             "\tif (%s != NULL && !svc_sendreply(%s, xdr_%s, %s)) {\n",
  248.             RESULT, TRANSP, RESULT, RESULT);
  249.         printerr("systemerr", TRANSP);
  250.         f_print(fout, "\t}\n");
  251.  
  252.         printif("freeargs", TRANSP, "&", ARG);
  253.         f_print(fout, "\t\tfprintf(stderr, \"unable to free arguments\\n\");\n");
  254.         f_print(fout, "\t\texit(1);\n");
  255.         f_print(fout, "\t}\n");
  256.  
  257.         f_print(fout, "}\n\n");
  258.     }
  259. }
  260.  
  261. static
  262. printerr(err, transp)
  263.     char *err;
  264.     char *transp;
  265. {
  266.     f_print(fout, "\t\tsvcerr_%s(%s);\n", err, transp);
  267. }
  268.  
  269. static
  270. printif(proc, transp, prefix, arg)
  271.     char *proc;
  272.     char *transp;
  273.     char *prefix;
  274.     char *arg;
  275. {
  276.     f_print(fout, "\tif (!svc_%s(%s, xdr_%s, %s%s)) {\n",
  277.         proc, transp, arg, prefix, arg);
  278. }
  279.  
  280.  
  281. nullproc(proc)
  282.     proc_list *proc;
  283. {
  284.     for (; proc != NULL; proc = proc->next) {
  285.         if (streq(proc->proc_num, "0")) {
  286.             return (1);
  287.         }
  288.     }
  289.     return (0);
  290. }
  291. Funky_Stuff
  292. len=`wc -c < rpc_svcout.c`
  293. if [ $len !=     7245 ] ; then
  294.   echo error: rpc_svcout.c was $len bytes long, should have been     7245
  295. fi
  296. echo x - rpc_util.c
  297. cat > rpc_util.c <<'Funky_Stuff'
  298. /* @(#)rpc_util.c    1.2 87/11/24 3.9 RPCSRC */
  299. /*
  300.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  301.  * unrestricted use provided that this legend is included on all tape
  302.  * media and as a part of the software program in whole or part.  Users
  303.  * may copy or modify Sun RPC without charge, but are not authorized
  304.  * to license or distribute it to anyone else except as part of a product or
  305.  * program developed by the user.
  306.  * 
  307.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  308.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  309.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  310.  * 
  311.  * Sun RPC is provided with no support and without any obligation on the
  312.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  313.  * modification or enhancement.
  314.  * 
  315.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  316.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  317.  * OR ANY PART THEREOF.
  318.  * 
  319.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  320.  * or profits or other special, indirect and consequential damages, even if
  321.  * Sun has been advised of the possibility of such damages.
  322.  * 
  323.  * Sun Microsystems, Inc.
  324.  * 2550 Garcia Avenue
  325.  * Mountain View, California  94043
  326.  */
  327. #ifndef lint
  328. static char sccsid[] = "@(#)rpc_util.c 1.5 87/06/24 (C) 1987 SMI";
  329. #endif
  330.  
  331. /*
  332.  * rpc_util.c, Utility routines for the RPC protocol compiler 
  333.  * Copyright (C) 1987, Sun Microsystems, Inc. 
  334.  */
  335. #include <stdio.h>
  336. #include "rpc_scan.h"
  337. #include "rpc_parse.h"
  338. #include "rpc_util.h"
  339.  
  340. char curline[MAXLINESIZE];    /* current read line */
  341. char *where = curline;    /* current point in line */
  342. int linenum = 0;    /* current line number */
  343.  
  344. char *infilename;    /* input filename */
  345.  
  346. #define NFILES 4
  347. char *outfiles[NFILES];    /* output file names */
  348. int nfiles;
  349.  
  350. FILE *fout;    /* file pointer of current output */
  351. FILE *fin;    /* file pointer of current input */
  352.  
  353. list *defined;    /* list of defined things */
  354.  
  355. /*
  356.  * Reinitialize the world 
  357.  */
  358. reinitialize()
  359. {
  360.     bzero(curline, MAXLINESIZE);
  361.     where = curline;
  362.     linenum = 0;
  363.     defined = NULL;
  364. }
  365.  
  366. /*
  367.  * string equality 
  368.  */
  369. streq(a, b)
  370.     char *a;
  371.     char *b;
  372. {
  373.     return (strcmp(a, b) == 0);
  374. }
  375.  
  376. /*
  377.  * find a value in a list 
  378.  */
  379. char *
  380. findval(lst, val, cmp)
  381.     list *lst;
  382.     char *val;
  383.     int (*cmp) ();
  384.  
  385. {
  386.     for (; lst != NULL; lst = lst->next) {
  387.         if ((*cmp) (lst->val, val)) {
  388.             return (lst->val);
  389.         }
  390.     }
  391.     return (NULL);
  392. }
  393.  
  394. /*
  395.  * store a value in a list 
  396.  */
  397. void
  398. storeval(lstp, val)
  399.     list **lstp;
  400.     char *val;
  401. {
  402.     list **l;
  403.     list *lst;
  404.  
  405.     for (l = lstp; *l != NULL; l = (list **) & (*l)->next);
  406.     lst = ALLOC(list);
  407.     lst->val = val;
  408.     lst->next = NULL;
  409.     *l = lst;
  410. }
  411.  
  412.  
  413. static
  414. findit(def, type)
  415.     definition *def;
  416.     char *type;
  417. {
  418.     return (streq(def->def_name, type));
  419. }
  420.  
  421.  
  422. static char *
  423. fixit(type, orig)
  424.     char *type;
  425.     char *orig;
  426. {
  427.     definition *def;
  428.  
  429.     def = (definition *) FINDVAL(defined, type, findit);
  430.     if (def == NULL || def->def_kind != DEF_TYPEDEF) {
  431.         return (orig);
  432.     }
  433.     switch (def->def.ty.rel) {
  434.     case REL_VECTOR:
  435.         return (def->def.ty.old_type);
  436.     case REL_ALIAS:
  437.         return (fixit(def->def.ty.old_type, orig));
  438.     default:
  439.         return (orig);
  440.     }
  441. }
  442.  
  443. char *
  444. fixtype(type)
  445.     char *type;
  446. {
  447.     return (fixit(type, type));
  448. }
  449.  
  450. char *
  451. stringfix(type)
  452.     char *type;
  453. {
  454.     if (streq(type, "string")) {
  455.         return ("wrapstring");
  456.     } else {
  457.         return (type);
  458.     }
  459. }
  460.  
  461. void
  462. ptype(prefix, type, follow)
  463.     char *prefix;
  464.     char *type;
  465.     int follow;
  466. {
  467.     if (prefix != NULL) {
  468.         if (streq(prefix, "enum")) {
  469.             f_print(fout, "enum ");
  470.         } else {
  471.             f_print(fout, "struct ");
  472.         }
  473.     }
  474.     if (streq(type, "bool")) {
  475.         f_print(fout, "bool_t ");
  476.     } else if (streq(type, "string")) {
  477.         f_print(fout, "char *");
  478.     } else {
  479.         f_print(fout, "%s ", follow ? fixtype(type) : type);
  480.     }
  481. }
  482.  
  483.  
  484. static
  485. typedefed(def, type)
  486.     definition *def;
  487.     char *type;
  488. {
  489.     if (def->def_kind != DEF_TYPEDEF || def->def.ty.old_prefix != NULL) {
  490.         return (0);
  491.     } else {
  492.         return (streq(def->def_name, type));
  493.     }
  494. }
  495.  
  496. isvectordef(type, rel)
  497.     char *type;
  498.     relation rel;
  499. {
  500.     definition *def;
  501.  
  502.     for (;;) {
  503.         switch (rel) {
  504.         case REL_VECTOR:
  505.             return (!streq(type, "string"));
  506.         case REL_ARRAY:
  507.             return (0);
  508.         case REL_POINTER:
  509.             return (0);
  510.         case REL_ALIAS:
  511.             def = (definition *) FINDVAL(defined, type, typedefed);
  512.             if (def == NULL) {
  513.                 return (0);
  514.             }
  515.             type = def->def.ty.old_type;
  516.             rel = def->def.ty.rel;
  517.         }
  518.     }
  519. }
  520.  
  521.  
  522. static char *
  523. locase(str)
  524.     char *str;
  525. {
  526.     char c;
  527.     static char buf[100];
  528.     char *p = buf;
  529.  
  530.     while (c = *str++) {
  531.         *p++ = (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c;
  532.     }
  533.     *p = 0;
  534.     return (buf);
  535. }
  536.  
  537.  
  538. void
  539. pvname(pname, vnum)
  540.     char *pname;
  541.     char *vnum;
  542. {
  543.     f_print(fout, "%s_%s", locase(pname), vnum);
  544. }
  545.  
  546.  
  547. /*
  548.  * print a useful (?) error message, and then die 
  549.  */
  550. void
  551. error(msg)
  552.     char *msg;
  553. {
  554.     printwhere();
  555.     f_print(stderr, "%s, line %d: ", infilename, linenum);
  556.     f_print(stderr, "%s\n", msg);
  557.     crash();
  558. }
  559.  
  560. /*
  561.  * Something went wrong, unlink any files that we may have created and then
  562.  * die. 
  563.  */
  564. crash()
  565. {
  566.     int i;
  567.  
  568.     for (i = 0; i < nfiles; i++) {
  569.         (void) unlink(outfiles[i]);
  570.     }
  571.     exit(1);
  572. }
  573.  
  574.  
  575. void
  576. record_open(file)
  577.     char *file;
  578. {
  579.     if (nfiles < NFILES) {
  580.         outfiles[nfiles++] = file;
  581.     } else {
  582.         f_print(stderr, "too many files!\n");
  583.         crash();
  584.     }
  585. }
  586.  
  587. static char expectbuf[100];
  588. static char *toktostr();
  589.  
  590. /*
  591.  * error, token encountered was not the expected one 
  592.  */
  593. void
  594. expected1(exp1)
  595.     tok_kind exp1;
  596. {
  597.     s_print(expectbuf, "expected '%s'",
  598.         toktostr(exp1));
  599.     error(expectbuf);
  600. }
  601.  
  602. /*
  603.  * error, token encountered was not one of two expected ones 
  604.  */
  605. void
  606. expected2(exp1, exp2)
  607.     tok_kind exp1, exp2;
  608. {
  609.     s_print(expectbuf, "expected '%s' or '%s'",
  610.         toktostr(exp1),
  611.         toktostr(exp2));
  612.     error(expectbuf);
  613. }
  614.  
  615. /*
  616.  * error, token encountered was not one of 3 expected ones 
  617.  */
  618. void
  619. expected3(exp1, exp2, exp3)
  620.     tok_kind exp1, exp2, exp3;
  621. {
  622.     s_print(expectbuf, "expected '%s', '%s' or '%s'",
  623.         toktostr(exp1),
  624.         toktostr(exp2),
  625.         toktostr(exp3));
  626.     error(expectbuf);
  627. }
  628.  
  629. void
  630. tabify(f, tab)
  631.     FILE *f;
  632.     int tab;
  633. {
  634.     while (tab--) {
  635.         (void) fputc('\t', f);
  636.     }
  637. }
  638.  
  639.  
  640.  
  641. static token tokstrings[] = {
  642.                  {TOK_IDENT, "identifier"},
  643.                  {TOK_CONST, "const"},
  644.                  {TOK_RPAREN, ")"},
  645.                  {TOK_LPAREN, "("},
  646.                  {TOK_RBRACE, "}"},
  647.                  {TOK_LBRACE, "{"},
  648.                  {TOK_LBRACKET, "["},
  649.                  {TOK_RBRACKET, "]"},
  650.                  {TOK_STAR, "*"},
  651.                  {TOK_COMMA, ","},
  652.                  {TOK_EQUAL, "="},
  653.                  {TOK_COLON, ":"},
  654.                  {TOK_SEMICOLON, ";"},
  655.                  {TOK_UNION, "union"},
  656.                  {TOK_STRUCT, "struct"},
  657.                  {TOK_SWITCH, "switch"},
  658.                  {TOK_CASE, "case"},
  659.                  {TOK_DEFAULT, "default"},
  660.                  {TOK_ENUM, "enum"},
  661.                  {TOK_TYPEDEF, "typedef"},
  662.                  {TOK_INT, "int"},
  663.                  {TOK_SHORT, "short"},
  664.                  {TOK_LONG, "long"},
  665.                  {TOK_UNSIGNED, "unsigned"},
  666.                  {TOK_DOUBLE, "double"},
  667.                  {TOK_FLOAT, "float"},
  668.                  {TOK_CHAR, "char"},
  669.                  {TOK_STRING, "string"},
  670.                  {TOK_OPAQUE, "opaque"},
  671.                  {TOK_BOOL, "bool"},
  672.                  {TOK_VOID, "void"},
  673.                  {TOK_PROGRAM, "program"},
  674.                  {TOK_VERSION, "version"},
  675.                  {TOK_EOF, "??????"}
  676. };
  677.  
  678. static char *
  679. toktostr(kind)
  680.     tok_kind kind;
  681. {
  682.     token *sp;
  683.  
  684.     for (sp = tokstrings; sp->kind != TOK_EOF && sp->kind != kind; sp++);
  685.     return (sp->str);
  686. }
  687.  
  688.  
  689.  
  690. static
  691. printbuf()
  692. {
  693.     char c;
  694.     int i;
  695.     int cnt;
  696.  
  697. #    define TABSIZE 4
  698.  
  699.     for (i = 0; c = curline[i]; i++) {
  700.         if (c == '\t') {
  701.             cnt = 8 - (i % TABSIZE);
  702.             c = ' ';
  703.         } else {
  704.             cnt = 1;
  705.         }
  706.         while (cnt--) {
  707.             (void) fputc(c, stderr);
  708.         }
  709.     }
  710. }
  711.  
  712.  
  713. static
  714. printwhere()
  715. {
  716.     int i;
  717.     char c;
  718.     int cnt;
  719.  
  720.     printbuf();
  721.     for (i = 0; i < where - curline; i++) {
  722.         c = curline[i];
  723.         if (c == '\t') {
  724.             cnt = 8 - (i % TABSIZE);
  725.         } else {
  726.             cnt = 1;
  727.         }
  728.         while (cnt--) {
  729.             (void) fputc('^', stderr);
  730.         }
  731.     }
  732.     (void) fputc('\n', stderr);
  733. }
  734. Funky_Stuff
  735. len=`wc -c < rpc_util.c`
  736. if [ $len !=     7773 ] ; then
  737.   echo error: rpc_util.c was $len bytes long, should have been     7773
  738. fi
  739. echo x - rpc_util.h
  740. cat > rpc_util.h <<'Funky_Stuff'
  741. /* @(#)rpc_util.h    1.2 87/11/24 3.9 RPCSRC */
  742. /*
  743.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  744.  * unrestricted use provided that this legend is included on all tape
  745.  * media and as a part of the software program in whole or part.  Users
  746.  * may copy or modify Sun RPC without charge, but are not authorized
  747.  * to license or distribute it to anyone else except as part of a product or
  748.  * program developed by the user.
  749.  * 
  750.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  751.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  752.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  753.  * 
  754.  * Sun RPC is provided with no support and without any obligation on the
  755.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  756.  * modification or enhancement.
  757.  * 
  758.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  759.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  760.  * OR ANY PART THEREOF.
  761.  * 
  762.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  763.  * or profits or other special, indirect and consequential damages, even if
  764.  * Sun has been advised of the possibility of such damages.
  765.  * 
  766.  * Sun Microsystems, Inc.
  767.  * 2550 Garcia Avenue
  768.  * Mountain View, California  94043
  769.  */
  770. /* @(#)rpc_util.h 1.6 87/06/24 (C) 1987 SMI */
  771.  
  772. /*
  773.  * rpc_util.h, Useful definitions for the RPC protocol compiler 
  774.  * Copyright (C) 1987, Sun Microsystems, Inc. 
  775.  */
  776. extern char *malloc();
  777.  
  778. #define alloc(size)        malloc((unsigned)(size))
  779. #define ALLOC(object)   (object *) malloc(sizeof(object))
  780.  
  781. extern char *sprintf();
  782.  
  783. #define s_print    (void) sprintf
  784. #define f_print (void) fprintf
  785.  
  786. struct list {
  787.     char *val;
  788.     struct list *next;
  789. };
  790. typedef struct list list;
  791.  
  792. /*
  793.  * Global variables 
  794.  */
  795. #define MAXLINESIZE 1024
  796. extern char curline[MAXLINESIZE];
  797. extern char *where;
  798. extern int linenum;
  799.  
  800. extern char *infilename;
  801. extern FILE *fout;
  802. extern FILE *fin;
  803.  
  804. extern list *defined;
  805.  
  806. /*
  807.  * rpc_util routines 
  808.  */
  809. void storeval();
  810.  
  811. #define STOREVAL(list,item)    \
  812.     storeval(list,(char *)item)
  813.  
  814. char *findval();
  815.  
  816. #define FINDVAL(list,item,finder) \
  817.     findval(list, (char *) item, finder)
  818.  
  819. char *fixtype();
  820. char *stringfix();
  821. void pvname();
  822. void ptype();
  823. int isvectordef();
  824. int streq();
  825. void error();
  826. void expected1();
  827. void expected2();
  828. void expected3();
  829. void tabify();
  830. void record_open();
  831.  
  832. /*
  833.  * rpc_cout routines 
  834.  */
  835. void cprint();
  836. void emit();
  837.  
  838. /*
  839.  * rpc_hout routines 
  840.  */
  841. void print_datadef();
  842.  
  843. /*
  844.  * rpc_svcout routines 
  845.  */
  846. void write_most();
  847. void write_register();
  848. void write_rest();
  849. void write_programs();
  850.  
  851. /*
  852.  * rpc_clntout routines
  853.  */
  854. void write_stubs();
  855. Funky_Stuff
  856. len=`wc -c < rpc_util.h`
  857. if [ $len !=     2666 ] ; then
  858.   echo error: rpc_util.h was $len bytes long, should have been     2666
  859. fi
  860. cd ..
  861. echo done with directory rpcgen
  862. echo x - rpcsvc
  863. echo creating directory rpcsvc
  864. mkdir rpcsvc
  865. cd rpcsvc
  866. echo x - Makefile
  867. cat > Makefile <<'Funky_Stuff'
  868. #
  869. # @(#)Makefile    1.6 87/11/30 3.9 RPCSRC
  870. #
  871. #
  872. RPCCOM = rpcgen
  873. LIB = -lrpclib
  874.  
  875. DESTDIR=
  876.  
  877. HDRS= klm_prot.h mount.h nfs_prot.h nlm_prot.h rex.h rquota.h rnusers.h\
  878.       rquota.h rstat.h sm_inter.h spray.h yppasswd.h yp.h
  879. XFILES= bootparam_prot.x klm_prot.x mount.x nfs_prot.x nlm_prot.x \
  880.       rex.x rnusers.x rquota.x rstat.x sm_inter.x spray.x yppasswd.x yp.x
  881. BIN= rstat_svc
  882. GEN= rstat_svc.c rstat_xdr.c
  883.  
  884. all:    $(HDRS) $(BIN)
  885.  
  886. install: $(HDRS) $(XFILES)
  887.     @echo "Creating RPC service headers directory"
  888.     -mkdir ${DESTDIR}/usr/include/rpcsvc && \
  889.         chown bin ${DESTDIR}/usr/include/rpcsvc && \
  890.         chmod 755 ${DESTDIR}/usr/include/rpcsvc
  891.     @echo "Installing RPC service header and definition files"
  892.     for i in $(HDRS) $(XFILES); do \
  893.         (install -c -m 644 $$i ${DESTDIR}/usr/include/rpcsvc) done
  894.     -mkdir ${DESTDIR}/etc && chown bin ${DESTDIR}/etc && \
  895.         chmod 755 ${DESTDIR}/etc
  896.     @echo "Installing RPC services in ${DESTDIR}/etc"
  897.     @set -x;for i in ${BIN}; do \
  898.         (install -c -s $$i ${DESTDIR}/etc/$$i); done
  899.  
  900. rstat_svc: rstat_proc.o rstat_svc.o rstat_xdr.o
  901.     $(CC) $(LDFLAGS) -o $@ rstat_proc.o rstat_svc.o rstat_xdr.o $(LIB)
  902.  
  903. rstat_proc.c:    rstat.h
  904.  
  905. klm_prot.h:
  906.     $(RPCCOM) -h klm_prot.x -o $@
  907. mount.h:
  908.     $(RPCCOM) -h mount.x -o $@
  909. nfs_prot.h:
  910.     $(RPCCOM) -h nfs_prot.x -o $@
  911. nlm_prot.h:
  912.     $(RPCCOM) -h nlm_prot.x -o $@
  913. rex.h:
  914.     $(RPCCOM) -h rex.x -o $@
  915. rnusers.h:
  916.     $(RPCCOM) -h rnusers.x -o $@
  917. rquota.h:
  918.     $(RPCCOM) -h rquota.x -o $@
  919. rstat.h:
  920.     $(RPCCOM) -h rstat.x -o $@
  921. sm_inter.h:
  922.     $(RPCCOM) -h sm_inter.x -o $@
  923. spray.h:
  924.     $(RPCCOM) -h spray.x -o $@
  925. yp.h:
  926.     $(RPCCOM) -h yp.x -o $@
  927. yppasswd.h:
  928.     $(RPCCOM) -h yppasswd.x -o $@
  929.  
  930. rstat_svc.c:    rstat.x
  931.     $(RPCCOM) -s udp rstat.x -o $@
  932. rstat_xdr.c:    rstat.x
  933.     $(RPCCOM) -c rstat.x -o $@
  934.  
  935. clean cleanup:
  936.     rm -f *.o $(GEN) $(BIN)
  937. Funky_Stuff
  938. len=`wc -c < Makefile`
  939. if [ $len !=     1755 ] ; then
  940.   echo error: Makefile was $len bytes long, should have been     1755
  941. fi
  942. echo x - bootparam_prot.x
  943. cat > bootparam_prot.x <<'Funky_Stuff'
  944. /* @(#)bootparam_prot.x    1.2 87/11/12 3.9 RPCSRC */
  945. /* @(#)bootparam_prot.x 1.2 87/06/24 Copyr 1987 Sun Micro */
  946.  
  947. /*
  948.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  949.  * unrestricted use provided that this legend is included on all tape
  950.  * media and as a part of the software program in whole or part.  Users
  951.  * may copy or modify Sun RPC without charge, but are not authorized
  952.  * to license or distribute it to anyone else except as part of a product or
  953.  * program developed by the user.
  954.  * 
  955.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  956.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  957.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  958.  * 
  959.  * Sun RPC is provided with no support and without any obligation on the
  960.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  961.  * modification or enhancement.
  962.  * 
  963.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  964.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  965.  * OR ANY PART THEREOF.
  966.  * 
  967.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  968.  * or profits or other special, indirect and consequential damages, even if
  969.  * Sun has been advised of the possibility of such damages.
  970.  * 
  971.  * Sun Microsystems, Inc.
  972.  * 2550 Garcia Avenue
  973.  * Mountain View, California  94043
  974.  */
  975.  
  976. /*
  977.  * RPC for bootparms service.
  978.  * There are two procedures:
  979.  *   WHOAMI takes a net address and returns a client name and also a
  980.  *    likely net address for routing
  981.  *   GETFILE takes a client name and file identifier and returns the
  982.  *    server name, server net address and pathname for the file.
  983.  *   file identifiers typically include root, swap, pub and dump
  984.  */
  985.  
  986. #ifdef RPC_HDR
  987. %#include <rpc/types.h>
  988. %#include <sys/time.h>
  989. %#include <sys/errno.h>
  990. %#include <nfs/nfs.h>
  991. #endif
  992.  
  993. const MAX_MACHINE_NAME  = 255;
  994. const MAX_PATH_LEN    = 1024;
  995. const MAX_FILEID    = 32;
  996. const IP_ADDR_TYPE    = 1;
  997.  
  998. typedef    string    bp_machine_name_t<MAX_MACHINE_NAME>;
  999. typedef    string    bp_path_t<MAX_PATH_LEN>;
  1000. typedef    string    bp_fileid_t<MAX_FILEID>;
  1001.  
  1002. struct    ip_addr_t {
  1003.     char    net;
  1004.     char    host;
  1005.     char    lh;
  1006.     char    impno;
  1007. };
  1008.  
  1009. union bp_address switch (int address_type) {
  1010.     case IP_ADDR_TYPE:
  1011.         ip_addr_t    ip_addr;
  1012. };
  1013.  
  1014. struct bp_whoami_arg {
  1015.     bp_address        client_address;
  1016. };
  1017.  
  1018. struct bp_whoami_res {
  1019.     bp_machine_name_t    client_name;
  1020.     bp_machine_name_t    domain_name;
  1021.     bp_address        router_address;
  1022. };
  1023.  
  1024. struct bp_getfile_arg {
  1025.     bp_machine_name_t    client_name;
  1026.     bp_fileid_t        file_id;
  1027. };
  1028.     
  1029. struct bp_getfile_res {
  1030.     bp_machine_name_t    server_name;
  1031.     bp_address        server_address;
  1032.     bp_path_t        server_path;
  1033. };
  1034.  
  1035. program BOOTPARAMPROG {
  1036.     version BOOTPARAMVERS {
  1037.         bp_whoami_res    BOOTPARAMPROC_WHOAMI(bp_whoami_arg) = 1;
  1038.         bp_getfile_res    BOOTPARAMPROC_GETFILE(bp_getfile_arg) = 2;
  1039.     } = 1;
  1040. } = 100026;
  1041. Funky_Stuff
  1042. len=`wc -c < bootparam_prot.x`
  1043. if [ $len !=     2823 ] ; then
  1044.   echo error: bootparam_prot.x was $len bytes long, should have been     2823
  1045. fi
  1046. echo x - klm_prot.x
  1047. cat > klm_prot.x <<'Funky_Stuff'
  1048. /* @(#)klm_prot.x    1.2 87/11/12 3.9 RPCSRC */
  1049. /* @(#)klm_prot.x 1.7 87/07/08 Copyr 1987 Sun Micro */
  1050.  
  1051. /*
  1052.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  1053.  * unrestricted use provided that this legend is included on all tape
  1054.  * media and as a part of the software program in whole or part.  Users
  1055.  * may copy or modify Sun RPC without charge, but are not authorized
  1056.  * to license or distribute it to anyone else except as part of a product or
  1057.  * program developed by the user.
  1058.  * 
  1059.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  1060.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  1061.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  1062.  * 
  1063.  * Sun RPC is provided with no support and without any obligation on the
  1064.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  1065.  * modification or enhancement.
  1066.  * 
  1067.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  1068.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  1069.  * OR ANY PART THEREOF.
  1070.  * 
  1071.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  1072.  * or profits or other special, indirect and consequential damages, even if
  1073.  * Sun has been advised of the possibility of such damages.
  1074.  * 
  1075.  * Sun Microsystems, Inc.
  1076.  * 2550 Garcia Avenue
  1077.  * Mountain View, California  94043
  1078.  */
  1079.  
  1080. /*
  1081.  * Kernel/lock manager protocol definition
  1082.  * Copyright (C) 1986 Sun Microsystems, Inc.
  1083.  *
  1084.  * protocol used between the UNIX kernel (the "client") and the
  1085.  * local lock manager.  The local lock manager is a deamon running
  1086.  * above the kernel.
  1087.  */
  1088. program KLM_PROG {
  1089.     version KLM_VERS {
  1090.  
  1091.         klm_testrply    KLM_TEST (struct klm_testargs) =    1;
  1092.  
  1093.         klm_stat    KLM_LOCK (struct klm_lockargs) =    2;
  1094.  
  1095.         klm_stat    KLM_CANCEL (struct klm_lockargs) =    3;
  1096.         /* klm_granted=> the cancel request fails due to lock is already granted */
  1097.         /* klm_denied=> the cancel request successfully aborts
  1098. lock request  */
  1099.  
  1100.         klm_stat    KLM_UNLOCK (struct klm_unlockargs) =    4;
  1101.     } = 1;
  1102. } = 100020;
  1103.  
  1104. const    LM_MAXSTRLEN = 1024;
  1105.  
  1106. /*
  1107.  * lock manager status returns
  1108.  */
  1109. enum klm_stats {
  1110.     klm_granted = 0,    /* lock is granted */
  1111.     klm_denied = 1,        /* lock is denied */
  1112.     klm_denied_nolocks = 2, /* no lock entry available */
  1113.     klm_working = 3     /* lock is being processed */
  1114. };
  1115.  
  1116. /*
  1117.  * lock manager lock identifier
  1118.  */
  1119. struct klm_lock {
  1120.     string server_name<LM_MAXSTRLEN>;
  1121.     netobj fh;        /* a counted file handle */
  1122.     int pid;        /* holder of the lock */
  1123.     unsigned l_offset;    /* beginning offset of the lock */
  1124.     unsigned l_len;        /* byte length of the lock;
  1125.                  * zero means through end of file */
  1126. };
  1127.  
  1128. /*
  1129.  * lock holder identifier
  1130.  */
  1131. struct klm_holder {
  1132.     bool exclusive;        /* FALSE if shared lock */
  1133.     int svid;        /* holder of the lock (pid) */
  1134.     unsigned l_offset;    /* beginning offset of the lock */
  1135.     unsigned l_len;        /* byte length of the lock;
  1136.                  * zero means through end of file */
  1137. };
  1138.  
  1139. /*
  1140.  * reply to KLM_LOCK / KLM_UNLOCK / KLM_CANCEL
  1141.  */
  1142. struct klm_stat {
  1143.     klm_stats stat;
  1144. };
  1145.  
  1146. /*
  1147.  * reply to a KLM_TEST call
  1148.  */
  1149. union klm_testrply switch (klm_stats stat) {
  1150.     case klm_denied:
  1151.         struct klm_holder holder;
  1152.     default: /* All other cases return no arguments */
  1153.         void;
  1154. };
  1155.  
  1156.  
  1157. /*
  1158.  * arguments to KLM_LOCK
  1159.  */
  1160. struct klm_lockargs {
  1161.     bool block;
  1162.     bool exclusive;
  1163.     struct klm_lock alock;
  1164. };
  1165.  
  1166. /*
  1167.  * arguments to KLM_TEST
  1168.  */
  1169. struct klm_testargs {
  1170.     bool exclusive;
  1171.     struct klm_lock alock;
  1172. };
  1173.  
  1174. /*
  1175.  * arguments to KLM_UNLOCK
  1176.  */
  1177. struct klm_unlockargs {
  1178.     struct klm_lock alock;
  1179. };
  1180. Funky_Stuff
  1181. len=`wc -c < klm_prot.x`
  1182. if [ $len !=     3486 ] ; then
  1183.   echo error: klm_prot.x was $len bytes long, should have been     3486
  1184. fi
  1185. echo x - mount.x
  1186. cat > mount.x <<'Funky_Stuff'
  1187. /* @(#)mount.x    1.2 87/11/12 3.9 RPCSRC */
  1188. /* @(#)mount.x 1.2 87/09/18 Copyr 1987 Sun Micro */
  1189.  
  1190. /*
  1191.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  1192.  * unrestricted use provided that this legend is included on all tape
  1193.  * media and as a part of the software program in whole or part.  Users
  1194.  * may copy or modify Sun RPC without charge, but are not authorized
  1195.  * to license or distribute it to anyone else except as part of a product or
  1196.  * program developed by the user.
  1197.  * 
  1198.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  1199.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  1200.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  1201.  * 
  1202.  * Sun RPC is provided with no support and without any obligation on the
  1203.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  1204.  * modification or enhancement.
  1205.  * 
  1206.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  1207.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  1208.  * OR ANY PART THEREOF.
  1209.  * 
  1210.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  1211.  * or profits or other special, indirect and consequential damages, even if
  1212.  * Sun has been advised of the possibility of such damages.
  1213.  * 
  1214.  * Sun Microsystems, Inc.
  1215.  * 2550 Garcia Avenue
  1216.  * Mountain View, California  94043
  1217.  */
  1218.  
  1219. /*
  1220.  * Protocol description for the mount program
  1221.  */
  1222.  
  1223.  
  1224. const MNTPATHLEN = 1024;    /* maximum bytes in a pathname argument */
  1225. const MNTNAMLEN = 255;        /* maximum bytes in a name argument */
  1226. const FHSIZE = 32;        /* size in bytes of a file handle */
  1227.  
  1228. /*
  1229.  * The fhandle is the file handle that the server passes to the client.
  1230.  * All file operations are done using the file handles to refer to a file
  1231.  * or a directory. The file handle can contain whatever information the
  1232.  * server needs to distinguish an individual file.
  1233.  */
  1234. typedef opaque fhandle<FHSIZE>;    
  1235.  
  1236. /*
  1237.  * If a status of zero is returned, the call completed successfully, and 
  1238.  * a file handle for the directory follows. A non-zero status indicates
  1239.  * some sort of error. The status corresponds with UNIX error numbers.
  1240.  */
  1241. union fhstatus switch (unsigned fhs_status) {
  1242. case 0:
  1243.     fhandle fhs_fhandle;
  1244. default:
  1245.     void;
  1246. };
  1247.  
  1248. /*
  1249.  * The type dirpath is the pathname of a directory
  1250.  */
  1251. typedef string dirpath<MNTPATHLEN>;
  1252.  
  1253. /*
  1254.  * The type name is used for arbitrary names (hostnames, groupnames)
  1255.  */
  1256. typedef string name<MNTNAMLEN>;
  1257.  
  1258. /*
  1259.  * A list of who has what mounted
  1260.  */
  1261. struct mountlist {
  1262.     name ml_hostname;
  1263.     dirpath ml_directory;
  1264.     mountlist *ml_next;
  1265. };
  1266.  
  1267. /*
  1268.  * A list of netgroups
  1269.  */
  1270. typedef struct groupnode *groups;
  1271. struct groupnode {
  1272.     name gr_name;
  1273.     groups *gr_next;
  1274. };
  1275.  
  1276. /*
  1277.  * A list of what is exported and to whom
  1278.  */
  1279. struct exports {
  1280.     dirpath ex_dir;
  1281.     groups ex_groups;
  1282.     exports *ex_next;
  1283. };
  1284.  
  1285. program MOUNTPROG {
  1286.     /*
  1287.      * Version one of the mount protocol communicates with version two
  1288.      * of the NFS protocol. The only connecting point is the fhandle 
  1289.      * structure, which is the same for both protocols.
  1290.      */
  1291.     version MOUNTVERS {
  1292.         /*
  1293.          * Does no work. It is made available in all RPC services
  1294.          * to allow server reponse testing and timing
  1295.          */
  1296.         void
  1297.         MOUNTPROC_NULL(void) = 0;
  1298.  
  1299.         /*    
  1300.          * If fhs_status is 0, then fhs_fhandle contains the
  1301.           * file handle for the directory. This file handle may
  1302.          * be used in the NFS protocol. This procedure also adds
  1303.          * a new entry to the mount list for this client mounting
  1304.          * the directory.
  1305.          * Unix authentication required.
  1306.          */
  1307.         fhstatus 
  1308.         MOUNTPROC_MNT(dirpath) = 1;
  1309.  
  1310.         /*
  1311.          * Returns the list of remotely mounted filesystems. The 
  1312.          * mountlist contains one entry for each hostname and 
  1313.          * directory pair.
  1314.          */
  1315.         mountlist
  1316.         MOUNTPROC_DUMP(void) = 2;
  1317.  
  1318.         /*
  1319.          * Removes the mount list entry for the directory
  1320.          * Unix authentication required.
  1321.          */
  1322.         void
  1323.         MOUNTPROC_UMNT(dirpath) = 3;
  1324.  
  1325.         /*
  1326.          * Removes all of the mount list entries for this client
  1327.          * Unix authentication required.
  1328.          */
  1329.         void
  1330.         MOUNTPROC_UMNTALL(void) = 4;
  1331.  
  1332.         /*
  1333.          * Returns a list of all the exported filesystems, and which
  1334.          * machines are allowed to import it.
  1335.          */
  1336.         exports
  1337.         MOUNTPROC_EXPORT(void)  = 5;
  1338.     
  1339.         /*
  1340.          * Identical to MOUNTPROC_EXPORT above
  1341.          */
  1342.         exports
  1343.         MOUNTPROC_EXPORTALL(void) = 6;
  1344.     } = 1;
  1345. } = 100005;
  1346. Funky_Stuff
  1347. len=`wc -c < mount.x`
  1348. if [ $len !=     4293 ] ; then
  1349.   echo error: mount.x was $len bytes long, should have been     4293
  1350. fi
  1351. echo x - nfs_prot.x
  1352. cat > nfs_prot.x <<'Funky_Stuff'
  1353. /* @(#)nfs_prot.x    1.2 87/11/12 3.9 RPCSRC */
  1354.  
  1355. /*
  1356.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  1357.  * unrestricted use provided that this legend is included on all tape
  1358.  * media and as a part of the software program in whole or part.  Users
  1359.  * may copy or modify Sun RPC without charge, but are not authorized
  1360.  * to license or distribute it to anyone else except as part of a product or
  1361.  * program developed by the user.
  1362.  * 
  1363.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  1364.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  1365.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  1366.  * 
  1367.  * Sun RPC is provided with no support and without any obligation on the
  1368.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  1369.  * modification or enhancement.
  1370.  * 
  1371.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  1372.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  1373.  * OR ANY PART THEREOF.
  1374.  * 
  1375.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  1376.  * or profits or other special, indirect and consequential damages, even if
  1377.  * Sun has been advised of the possibility of such damages.
  1378.  * 
  1379.  * Sun Microsystems, Inc.
  1380.  * 2550 Garcia Avenue
  1381.  * Mountain View, California  94043
  1382.  */
  1383.  
  1384. /*
  1385.  * nfs_prot.x 1.2 87/10/12
  1386.  * Copyright 1987 Sun Microsystems, Inc.
  1387.  */
  1388. const NFS_PORT          = 2049;
  1389. const NFS_MAXDATA       = 8192;
  1390. const NFS_MAXPATHLEN    = 1024;
  1391. const NFS_MAXNAMLEN    = 255;
  1392. const NFS_FHSIZE    = 32;
  1393. const NFS_COOKIESIZE    = 4;
  1394. const NFS_FIFO_DEV    = -1;    /* size kludge for named pipes */
  1395.  
  1396. /*
  1397.  * File types
  1398.  */
  1399. const NFSMODE_FMT  = 0170000;    /* type of file */
  1400. const NFSMODE_DIR  = 0040000;    /* directory */
  1401. const NFSMODE_CHR  = 0020000;    /* character special */
  1402. const NFSMODE_BLK  = 0060000;    /* block special */
  1403. const NFSMODE_REG  = 0100000;    /* regular */
  1404. const NFSMODE_LNK  = 0120000;    /* symbolic link */
  1405. const NFSMODE_SOCK = 0140000;    /* socket */
  1406. const NFSMODE_FIFO = 0010000;    /* fifo */
  1407.  
  1408. /*
  1409.  * Error status
  1410.  */
  1411. enum nfsstat {
  1412.     NFS_OK= 0,        /* no error */
  1413.     NFSERR_PERM=1,        /* Not owner */
  1414.     NFSERR_NOENT=2,        /* No such file or directory */
  1415.     NFSERR_IO=5,        /* I/O error */
  1416.     NFSERR_NXIO=6,        /* No such device or address */
  1417.     NFSERR_ACCES=13,    /* Permission denied */
  1418.     NFSERR_EXIST=17,    /* File exists */
  1419.     NFSERR_NODEV=19,    /* No such device */
  1420.     NFSERR_NOTDIR=20,    /* Not a directory*/
  1421.     NFSERR_ISDIR=21,    /* Is a directory */
  1422.     NFSERR_FBIG=27,        /* File too large */
  1423.     NFSERR_NOSPC=28,    /* No space left on device */
  1424.     NFSERR_ROFS=30,        /* Read-only file system */
  1425.     NFSERR_NAMETOOLONG=63,    /* File name too long */
  1426.     NFSERR_NOTEMPTY=66,    /* Directory not empty */
  1427.     NFSERR_DQUOT=69,    /* Disc quota exceeded */
  1428.     NFSERR_STALE=70,    /* Stale NFS file handle */
  1429.     NFSERR_WFLUSH=99    /* write cache flushed */
  1430. };
  1431.  
  1432. /*
  1433.  * File types
  1434.  */
  1435. enum ftype {
  1436.     NFNON = 0,    /* non-file */
  1437.     NFREG = 1,    /* regular file */
  1438.     NFDIR = 2,    /* directory */
  1439.     NFBLK = 3,    /* block special */
  1440.     NFCHR = 4,    /* character special */
  1441.     NFLNK = 5,    /* symbolic link */
  1442.     NFSOCK = 6,    /* unix domain sockets */
  1443.     NFBAD = 7,    /* unused */
  1444.     NFFIFO = 8     /* named pipe */
  1445. };
  1446.  
  1447. /*
  1448.  * File access handle
  1449.  */
  1450. struct nfs_fh {
  1451.     opaque data[NFS_FHSIZE];
  1452. };
  1453.  
  1454. /* 
  1455.  * Timeval
  1456.  */
  1457. struct nfstime {
  1458.     unsigned seconds;
  1459.     unsigned useconds;
  1460. };
  1461.  
  1462.  
  1463. /*
  1464.  * File attributes
  1465.  */
  1466. struct fattr {
  1467.     ftype type;        /* file type */
  1468.     unsigned mode;        /* protection mode bits */
  1469.     unsigned nlink;        /* # hard links */
  1470.     unsigned uid;        /* owner user id */
  1471.     unsigned gid;        /* owner group id */
  1472.     unsigned size;        /* file size in bytes */
  1473.     unsigned blocksize;    /* prefered block size */
  1474.     unsigned rdev;        /* special device # */
  1475.     unsigned blocks;    /* Kb of disk used by file */
  1476.     unsigned fsid;        /* device # */
  1477.     unsigned fileid;    /* inode # */
  1478.     nfstime    atime;        /* time of last access */
  1479.     nfstime    mtime;        /* time of last modification */
  1480.     nfstime    ctime;        /* time of last change */
  1481. };
  1482.  
  1483. /*
  1484.  * File attributes which can be set
  1485.  */
  1486. struct sattr {
  1487.     unsigned mode;    /* protection mode bits */
  1488.     unsigned uid;    /* owner user id */
  1489.     unsigned gid;    /* owner group id */
  1490.     unsigned size;    /* file size in bytes */
  1491.     nfstime    atime;    /* time of last access */
  1492.     nfstime    mtime;    /* time of last modification */
  1493. };
  1494.  
  1495.  
  1496. typedef string filename<NFS_MAXNAMLEN>; 
  1497. typedef string nfspath<NFS_MAXPATHLEN>;
  1498.  
  1499. /*
  1500.  * Reply status with file attributes
  1501.  */
  1502. union attrstat switch (nfsstat status) {
  1503. case NFS_OK:
  1504.     fattr attributes;
  1505. default:
  1506.     void;
  1507. };
  1508.  
  1509. struct sattrargs {
  1510.     nfs_fh file;
  1511.     sattr attributes;
  1512. };
  1513.  
  1514. /*
  1515.  * Arguments for directory operations
  1516.  */
  1517. struct diropargs {
  1518.     nfs_fh    dir;    /* directory file handle */
  1519.     filename name;        /* name (up to NFS_MAXNAMLEN bytes) */
  1520. };
  1521.  
  1522. struct diropokres {
  1523.     nfs_fh file;
  1524.     fattr attributes;
  1525. };
  1526.  
  1527. /*
  1528.  * Results from directory operation
  1529.  */
  1530. union diropres switch (nfsstat status) {
  1531. case NFS_OK:
  1532.     diropokres diropres;
  1533. default:
  1534.     void;
  1535. };
  1536.  
  1537. union readlinkres switch (nfsstat status) {
  1538. case NFS_OK:
  1539.     nfspath data;
  1540. default:
  1541.     void;
  1542. };
  1543.  
  1544. /*
  1545.  * Arguments to remote read
  1546.  */
  1547. struct readargs {
  1548.     nfs_fh file;        /* handle for file */
  1549.     unsigned offset;    /* byte offset in file */
  1550.     unsigned count;        /* immediate read count */
  1551.     unsigned totalcount;    /* total read count (from this offset)*/
  1552. };
  1553.  
  1554. /*
  1555.  * Status OK portion of remote read reply
  1556.  */
  1557. struct readokres {
  1558.     fattr    attributes;    /* attributes, need for pagin*/
  1559.     opaque data<NFS_MAXDATA>;
  1560. };
  1561.  
  1562. union readres switch (nfsstat status) {
  1563. case NFS_OK:
  1564.     readokres reply;
  1565. default:
  1566.     void;
  1567. };
  1568.  
  1569. /*
  1570.  * Arguments to remote write 
  1571.  */
  1572. struct writeargs {
  1573.     nfs_fh    file;        /* handle for file */
  1574.     unsigned beginoffset;    /* beginning byte offset in file */
  1575.     unsigned offset;    /* current byte offset in file */
  1576.     unsigned totalcount;    /* total write count (to this offset)*/
  1577.     opaque data<NFS_MAXDATA>;
  1578. };
  1579.  
  1580. struct createargs {
  1581.     diropargs where;
  1582.     sattr attributes;
  1583. };
  1584.  
  1585. struct renameargs {
  1586.     diropargs from;
  1587.     diropargs to;
  1588. };
  1589.  
  1590. struct linkargs {
  1591.     nfs_fh from;
  1592.     diropargs to;
  1593. };
  1594.  
  1595. struct symlinkargs {
  1596.     diropargs from;
  1597.     nfspath to;
  1598.     sattr attributes;
  1599. };
  1600.  
  1601.  
  1602. typedef opaque nfscookie[NFS_COOKIESIZE];
  1603.  
  1604. /*
  1605.  * Arguments to readdir
  1606.  */
  1607. struct readdirargs {
  1608.     nfs_fh dir;        /* directory handle */
  1609.     nfscookie cookie;
  1610.     unsigned count;        /* number of directory bytes to read */
  1611. };
  1612.  
  1613. struct entry {
  1614.     unsigned fileid;
  1615.     filename name;
  1616.     nfscookie cookie;
  1617.     entry *nextentry;
  1618. };
  1619.  
  1620. struct dirlist {
  1621.     entry *entries;
  1622.     bool eof;
  1623. };
  1624.  
  1625. union readdirres switch (nfsstat status) {
  1626. case NFS_OK:
  1627.     dirlist reply;
  1628. default:
  1629.     void;
  1630. };
  1631.  
  1632. struct statfsokres {
  1633.     unsigned tsize;    /* preferred transfer size in bytes */
  1634.     unsigned bsize;    /* fundamental file system block size */
  1635.     unsigned blocks;    /* total blocks in file system */
  1636.     unsigned bfree;    /* free blocks in fs */
  1637.     unsigned bavail;    /* free blocks avail to non-superuser */
  1638. };
  1639.  
  1640. union statfsres switch (nfsstat status) {
  1641. case NFS_OK:
  1642.     statfsokres reply;
  1643. default:
  1644.     void;
  1645. };
  1646.  
  1647. /*
  1648.  * Remote file service routines
  1649.  */
  1650. program NFS_PROGRAM {
  1651.     version NFS_VERSION {
  1652.         void 
  1653.         NFSPROC_NULL(void) = 0;
  1654.  
  1655.         attrstat 
  1656.         NFSPROC_GETATTR(nfs_fh) =    1;
  1657.  
  1658.         attrstat 
  1659.         NFSPROC_SETATTR(sattrargs) = 2;
  1660.  
  1661.         void 
  1662.         NFSPROC_ROOT(void) = 3;
  1663.  
  1664.         diropres 
  1665.         NFSPROC_LOOKUP(diropargs) = 4;
  1666.  
  1667.         readlinkres 
  1668.         NFSPROC_READLINK(nfs_fh) = 5;
  1669.  
  1670.         readres 
  1671.         NFSPROC_READ(readargs) = 6;
  1672.  
  1673.         void 
  1674.         NFSPROC_WRITECACHE(void) = 7;
  1675.  
  1676.         attrstat
  1677.         NFSPROC_WRITE(writeargs) = 8;
  1678.  
  1679.         diropres
  1680.         NFSPROC_CREATE(createargs) = 9;
  1681.  
  1682.         nfsstat
  1683.         NFSPROC_REMOVE(diropargs) = 10;
  1684.  
  1685.         nfsstat
  1686.         NFSPROC_RENAME(renameargs) = 11;
  1687.  
  1688.         nfsstat
  1689.         NFSPROC_LINK(linkargs) = 12;
  1690.  
  1691.         nfsstat
  1692.         NFSPROC_SYMLINK(symlinkargs) = 13;
  1693.  
  1694.         diropres
  1695.         NFSPROC_MKDIR(createargs) = 14;
  1696.  
  1697.         nfsstat
  1698.         NFSPROC_RMDIR(diropargs) = 15;
  1699.  
  1700.         readdirres
  1701.         NFSPROC_READDIR(readdirargs) = 16;
  1702.  
  1703.         statfsres
  1704.         NFSPROC_STATFS(nfs_fh) = 17;
  1705.     } = 2;
  1706. } = 100003;
  1707.  
  1708. Funky_Stuff
  1709. len=`wc -c < nfs_prot.x`
  1710. if [ $len !=     7684 ] ; then
  1711.   echo error: nfs_prot.x was $len bytes long, should have been     7684
  1712. fi
  1713. echo x - nlm_prot.x
  1714. cat > nlm_prot.x <<'Funky_Stuff'
  1715. /* @(#)nlm_prot.x    1.2 87/11/12 3.9 RPCSRC */
  1716. /* @(#)nlm_prot.x 1.8 87/09/21 Copyr 1987 Sun Micro */
  1717.  
  1718. /*
  1719.  * Network lock manager protocol definition
  1720.  * Copyright (C) 1986 Sun Microsystems, Inc.
  1721.  *
  1722.  * protocol used between local lock manager and remote lock manager
  1723.  */
  1724.  
  1725. #ifdef RPC_HDR
  1726. %#define LM_MAXSTRLEN    1024
  1727. %#define MAXNAMELEN    LM_MAXSTRLEN+1
  1728. #endif
  1729.  
  1730. /*
  1731.  * status of a call to the lock manager
  1732.  */
  1733. enum nlm_stats {
  1734.     nlm_granted = 0,
  1735.     nlm_denied = 1,
  1736.     nlm_denied_nolocks = 2,
  1737.     nlm_blocked = 3,
  1738.     nlm_denied_grace_period = 4
  1739. };
  1740.  
  1741. struct nlm_holder {
  1742.     bool exclusive;
  1743.     int svid;
  1744.     netobj oh;
  1745.     unsigned l_offset;
  1746.     unsigned l_len;
  1747. };
  1748.  
  1749. union nlm_testrply switch (nlm_stats stat) {
  1750.     case nlm_denied:
  1751.         struct nlm_holder holder;
  1752.     default:
  1753.         void;
  1754. };
  1755.  
  1756. struct nlm_stat {
  1757.     nlm_stats stat;
  1758. };
  1759.  
  1760. struct nlm_res {
  1761.     netobj cookie;
  1762.     nlm_stat stat;
  1763. };
  1764.  
  1765. struct nlm_testres {
  1766.     netobj cookie;
  1767.     nlm_testrply stat;
  1768. };
  1769.  
  1770. struct nlm_lock {
  1771.     string caller_name<LM_MAXSTRLEN>;
  1772.     netobj fh;        /* identify a file */
  1773.     netobj oh;        /* identify owner of a lock */
  1774.     int svid;        /* generated from pid for svid */
  1775.     unsigned l_offset;
  1776.     unsigned l_len;
  1777. };
  1778.  
  1779. struct nlm_lockargs {
  1780.     netobj cookie;
  1781.     bool block;
  1782.     bool exclusive;
  1783.     struct nlm_lock alock;
  1784.     bool reclaim;        /* used for recovering locks */
  1785.     int state;        /* specify local status monitor state */
  1786. };
  1787.  
  1788. struct nlm_cancargs {
  1789.     netobj cookie;        
  1790.     bool block;
  1791.     bool exclusive;
  1792.     struct nlm_lock alock;
  1793. };
  1794.  
  1795. struct nlm_testargs {
  1796.     netobj cookie;        
  1797.     bool exclusive;
  1798.     struct nlm_lock alock;
  1799. };
  1800.  
  1801. struct nlm_unlockargs {
  1802.     netobj cookie;        
  1803.     struct nlm_lock alock;
  1804. };
  1805.  
  1806.  
  1807. #ifdef RPC_HDR
  1808. %/*
  1809. % * The following enums are actually bit encoded for efficient
  1810. % * boolean algebra.... DON'T change them.....
  1811. % */
  1812. #endif
  1813. enum    fsh_mode {
  1814.     fsm_DN  = 0,    /* deny none */
  1815.     fsm_DR  = 1,    /* deny read */
  1816.     fsm_DW  = 2,    /* deny write */
  1817.     fsm_DRW = 3    /* deny read/write */
  1818. };
  1819.  
  1820. enum    fsh_access {
  1821.     fsa_NONE = 0,    /* for completeness */
  1822.     fsa_R    = 1,    /* read only */
  1823.     fsa_W    = 2,    /* write only */
  1824.     fsa_RW   = 3    /* read/write */
  1825. };
  1826.  
  1827. struct    nlm_share {
  1828.     string caller_name<LM_MAXSTRLEN>;
  1829.     netobj    fh;
  1830.     netobj    oh;
  1831.     fsh_mode    mode;
  1832.     fsh_access    access;
  1833. };
  1834.  
  1835. struct    nlm_shareargs {
  1836.     netobj    cookie;
  1837.     nlm_share    share;
  1838.     bool    reclaim;
  1839. };
  1840.  
  1841. struct    nlm_shareres {
  1842.     netobj    cookie;
  1843.     nlm_stats    stat;
  1844.     int    sequence;
  1845. };
  1846.  
  1847. struct    nlm_notify {
  1848.     string name<MAXNAMELEN>;
  1849.     long state;
  1850. };
  1851.  
  1852. /*
  1853.  * Over-the-wire protocol used between the network lock managers
  1854.  */
  1855.  
  1856. program NLM_PROG {
  1857.     version NLM_VERS {
  1858.  
  1859.         nlm_testres    NLM_TEST(struct nlm_testargs) =    1;
  1860.  
  1861.         nlm_res        NLM_LOCK(struct nlm_lockargs) =    2;
  1862.  
  1863.         nlm_res        NLM_CANCEL(struct nlm_cancargs) = 3;
  1864.         nlm_res        NLM_UNLOCK(struct nlm_unlockargs) =    4;
  1865.  
  1866.         /*
  1867.          * remote lock manager call-back to grant lock
  1868.          */
  1869.         nlm_res        NLM_GRANTED(struct nlm_testargs)= 5;
  1870.         /*
  1871.          * message passing style of requesting lock
  1872.          */
  1873.         void        NLM_TEST_MSG(struct nlm_testargs) = 6;
  1874.         void        NLM_LOCK_MSG(struct nlm_lockargs) = 7;
  1875.         void        NLM_CANCEL_MSG(struct nlm_cancargs) =8;
  1876.         void        NLM_UNLOCK_MSG(struct nlm_unlockargs) = 9;
  1877.         void        NLM_GRANTED_MSG(struct nlm_testargs) = 10;
  1878.         void        NLM_TEST_RES(nlm_testres) = 11;
  1879.         void        NLM_LOCK_RES(nlm_res) = 12;
  1880.         void        NLM_CANCEL_RES(nlm_res) = 13;
  1881.         void        NLM_UNLOCK_RES(nlm_res) = 14;
  1882.         void        NLM_GRANTED_RES(nlm_res) = 15;
  1883.     } = 1;
  1884.  
  1885.     version NLM_VERSX {
  1886.         nlm_shareres    NLM_SHARE(nlm_shareargs) = 20;
  1887.         nlm_shareres    NLM_UNSHARE(nlm_shareargs) = 21;
  1888.         nlm_res        NLM_NM_LOCK(nlm_lockargs) = 22;
  1889.         void        NLM_FREE_ALL(nlm_notify) = 23;
  1890.     } = 3;
  1891.  
  1892. } = 100021;
  1893.  
  1894. Funky_Stuff
  1895. len=`wc -c < nlm_prot.x`
  1896. if [ $len !=     3476 ] ; then
  1897.   echo error: nlm_prot.x was $len bytes long, should have been     3476
  1898. fi
  1899. echo x - rex.x
  1900. cat > rex.x <<'Funky_Stuff'
  1901. /* @(#)rex.x    1.2 87/11/12 3.9 RPCSRC */
  1902. /* @(#)rex.x 1.3 87/09/18 Copyr 1987 Sun Micro */
  1903.  
  1904. /*
  1905.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  1906.  * unrestricted use provided that this legend is included on all tape
  1907.  * media and as a part of the software program in whole or part.  Users
  1908.  * may copy or modify Sun RPC without charge, but are not authorized
  1909.  * to license or distribute it to anyone else except as part of a product or
  1910.  * program developed by the user.
  1911.  * 
  1912.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  1913.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  1914.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  1915.  * 
  1916.  * Sun RPC is provided with no support and without any obligation on the
  1917.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  1918.  * modification or enhancement.
  1919.  * 
  1920.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  1921.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  1922.  * OR ANY PART THEREOF.
  1923.  * 
  1924.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  1925.  * or profits or other special, indirect and consequential damages, even if
  1926.  * Sun has been advised of the possibility of such damages.
  1927.  * 
  1928.  * Sun Microsystems, Inc.
  1929.  * 2550 Garcia Avenue
  1930.  * Mountain View, California  94043
  1931.  */
  1932.  
  1933. /*
  1934.  * Remote execution (rex) protocol specification
  1935.  */
  1936.  
  1937. const STRINGSIZE = 1024;
  1938. typedef string rexstring<1024>;
  1939.  
  1940. /*
  1941.  * values to pass to REXPROC_SIGNAL
  1942.  */
  1943. const SIGINT = 2;    /* interrupt */
  1944.  
  1945. /*
  1946.  * Values for rst_flags, below 
  1947.  */
  1948. const REX_INTERACTIVE = 1;    /* interactive mode */
  1949.  
  1950. struct rex_start {
  1951.     rexstring rst_cmd<>;    /* list of command and args */
  1952.     rexstring rst_host;    /* working directory host name */
  1953.     rexstring rst_fsname;    /* working directory file system name */
  1954.     rexstring rst_dirwithin;/* working directory within file system */
  1955.     rexstring rst_env<>;    /* list of environment */
  1956.     unsigned int rst_port0;    /* port for stdin */
  1957.     unsigned int rst_port1;    /* port for stdout */
  1958.     unsigned int rst_port2;    /* port for stderr */
  1959.     unsigned int rst_flags;    /* options - see const above */
  1960. };
  1961.  
  1962. struct rex_result {
  1963.        int rlt_stat;        /* integer status code */
  1964.     rexstring rlt_message;    /* string message for human consumption */
  1965. };
  1966.  
  1967.  
  1968. struct sgttyb {
  1969.     unsigned four;    /* always equals 4 */
  1970.     opaque chars[4];
  1971.     /* chars[0] == input speed */
  1972.     /* chars[1] == output speed */
  1973.     /* chars[2] == kill character */
  1974.     /* chars[3] == erase character */
  1975.     unsigned flags;
  1976. };
  1977. /* values for speeds above (baud rates)  */
  1978. const B0  = 0;
  1979. const B50 = 1;
  1980. const B75 = 2;
  1981. const B110 = 3;
  1982. const B134 = 4;
  1983. const B150 = 5;
  1984. const B200 = 6;
  1985. const B300 = 7;
  1986. const B600 = 8;
  1987. const B1200 = 9;
  1988. const B1800 = 10;
  1989. const B2400 = 11;
  1990. const B4800 = 12;
  1991. const B9600 = 13;
  1992. const B19200 = 14;
  1993. const B38400 = 15;
  1994.  
  1995. /* values for flags above */
  1996. const TANDEM = 0x00000001; /* send stopc on out q full */
  1997. const CBREAK = 0x00000002; /* half-cooked mode */
  1998. const LCASE = 0x00000004; /* simulate lower case */
  1999. const ECHO = 0x00000008; /* echo input */
  2000. const CRMOD = 0x00000010; /* map \r to \r\n on output */
  2001. const RAW = 0x00000020; /* no i/o processing */
  2002. const ODDP = 0x00000040; /* get/send odd parity */
  2003. const EVENP = 0x00000080; /* get/send even parity */
  2004. const ANYP = 0x000000c0; /* get any parity/send none */
  2005. const NLDELAY = 0x00000300; /* \n delay */
  2006. const  NL0 = 0x00000000;
  2007. const  NL1 = 0x00000100; /* tty 37 */
  2008. const  NL2 = 0x00000200; /* vt05 */
  2009. const  NL3 = 0x00000300;
  2010. const TBDELAY = 0x00000c00; /* horizontal tab delay */
  2011. const  TAB0 = 0x00000000;
  2012. const  TAB1 = 0x00000400; /* tty 37 */
  2013. const  TAB2 = 0x00000800;
  2014. const XTABS = 0x00000c00; /* expand tabs on output */
  2015. const CRDELAY = 0x00003000; /* \r delay */
  2016. const  CR0 = 0x00000000;
  2017. const  CR1 = 0x00001000; /* tn 300 */
  2018. const  CR2 = 0x00002000; /* tty 37 */
  2019. const  CR3 = 0x00003000; /* concept 100 */
  2020. const VTDELAY = 0x00004000; /* vertical tab delay */
  2021. const  FF0 = 0x00000000;
  2022. const  FF1 = 0x00004000; /* tty 37 */
  2023. const BSDELAY = 0x00008000; /* \b delay */
  2024. const  BS0 = 0x00000000;
  2025. const  BS1 = 0x00008000;
  2026. const CRTBS = 0x00010000; /* do backspacing for crt */
  2027. const PRTERA = 0x00020000; /* \ ... / erase */
  2028. const CRTERA = 0x00040000; /* " \b " to wipe out char */
  2029. const TILDE = 0x00080000; /* hazeltine tilde kludge */
  2030. const MDMBUF = 0x00100000; /* start/stop output on carrier intr */
  2031. const LITOUT = 0x00200000; /* literal output */
  2032. const TOSTOP = 0x00400000; /* SIGTTOU on background output */
  2033. const FLUSHO = 0x00800000; /* flush output to terminal */
  2034. const NOHANG = 0x01000000; /* no SIGHUP on carrier drop */
  2035. const L001000 = 0x02000000;
  2036. const CRTKIL = 0x04000000; /* kill line with " \b " */
  2037. const PASS8 = 0x08000000;
  2038. const CTLECH = 0x10000000; /* echo control chars as ^X */
  2039. const PENDIN = 0x20000000; /* tp->t_rawq needs reread */
  2040. const DECCTQ = 0x40000000; /* only ^Q starts after ^S */
  2041. const NOFLSH = 0x80000000; /* no output flush on signal */
  2042.  
  2043. struct tchars {
  2044.     unsigned six;    /* always equals 6 */
  2045.     opaque chars[6];
  2046.     /* chars[0] == interrupt char */
  2047.     /* chars[1] == quit char */
  2048.     /* chars[2] == start output char */
  2049.     /* chars[3] == stop output char */
  2050.     /* chars[4] == end-of-file char */
  2051.     /* chars[5] == input delimeter (like nl) */
  2052. };
  2053.  
  2054. struct ltchars {
  2055.     unsigned six;    /* always equals 6 */
  2056.     opaque chars[6];
  2057.     /* chars[0] == stop process signal */
  2058.     /* chars[1] == delayed stop process signal */
  2059.     /* chars[2] == reprint line */
  2060.     /* chars[3] == flush output */
  2061.     /* chars[4] == word erase */
  2062.     /* chars[5] == literal next character */
  2063.     unsigned mode;
  2064. };
  2065.  
  2066. struct rex_ttysize {
  2067.     int ts_lines;
  2068.     int ts_cols;
  2069. };
  2070.  
  2071. struct rex_ttymode {
  2072.     sgttyb basic;    /* standard unix tty flags */
  2073.     tchars more; /* interrupt, kill characters, etc. */
  2074.     ltchars yetmore; /* special Berkeley characters */
  2075.     unsigned andmore;     /* and Berkeley modes */
  2076. };
  2077.  
  2078. /* values for andmore above */
  2079. const LCRTBS = 0x0001;    /* do backspacing for crt */
  2080. const LPRTERA = 0x0002;    /* \ ... / erase */
  2081. const LCRTERA = 0x0004;    /* " \b " to wipe out char */
  2082. const LTILDE = 0x0008;    /* hazeltine tilde kludge */
  2083. const LMDMBUF = 0x0010;    /* start/stop output on carrier intr */
  2084. const LLITOUT = 0x0020;    /* literal output */
  2085. const LTOSTOP = 0x0040;    /* SIGTTOU on background output */
  2086. const LFLUSHO = 0x0080;    /* flush output to terminal */
  2087. const LNOHANG = 0x0100;    /* no SIGHUP on carrier drop */
  2088. const LL001000 = 0x0200;
  2089. const LCRTKIL = 0x0400;    /* kill line with " \b " */
  2090. const LPASS8 = 0x0800;
  2091. const LCTLECH = 0x1000;    /* echo control chars as ^X */
  2092. const LPENDIN = 0x2000;    /* needs reread */
  2093. const LDECCTQ = 0x4000;    /* only ^Q starts after ^S */
  2094. const LNOFLSH = 0x8000;    /* no output flush on signal */
  2095.  
  2096. program REXPROG {
  2097.     version REXVERS {
  2098.  
  2099.         /*
  2100.          * Start remote execution
  2101.          */
  2102.         rex_result 
  2103.         REXPROC_START(rex_start) = 1;
  2104.  
  2105.         /*
  2106.          * Wait for remote execution to terminate
  2107.          */
  2108.         rex_result
  2109.         REXPROC_WAIT(void) = 2;
  2110.  
  2111.         /*
  2112.          * Send tty modes
  2113.          */
  2114.         void
  2115.         REXPROC_MODES(rex_ttymode) = 3;
  2116.  
  2117.         /*
  2118.          * Send window size change
  2119.          */
  2120.         void
  2121.         REXPROC_WINCH(rex_ttysize) = 4;
  2122.  
  2123.         /*
  2124.          * Send other signal
  2125.          */
  2126.         void
  2127.         REXPROC_SIGNAL(int) = 5;
  2128.     } = 1;
  2129. } = 100017;
  2130. Funky_Stuff
  2131. len=`wc -c < rex.x`
  2132. if [ $len !=     7115 ] ; then
  2133.   echo error: rex.x was $len bytes long, should have been     7115
  2134. fi
  2135. echo x - rnusers.x
  2136. cat > rnusers.x <<'Funky_Stuff'
  2137. /* @(#)rnusers.x    1.2 87/11/12 3.9 RPCSRC */
  2138. /* @(#)rnusers.x 1.2 87/09/20 Copyr 1987 Sun Micro */
  2139.  
  2140. /*
  2141.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  2142.  * unrestricted use provided that this legend is included on all tape
  2143.  * media and as a part of the software program in whole or part.  Users
  2144.  * may copy or modify Sun RPC without charge, but are not authorized
  2145.  * to license or distribute it to anyone else except as part of a product or
  2146.  * program developed by the user.
  2147.  * 
  2148.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  2149.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  2150.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  2151.  * 
  2152.  * Sun RPC is provided with no support and without any obligation on the
  2153.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  2154.  * modification or enhancement.
  2155.  * 
  2156.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  2157.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  2158.  * OR ANY PART THEREOF.
  2159.  * 
  2160.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  2161.  * or profits or other special, indirect and consequential damages, even if
  2162.  * Sun has been advised of the possibility of such damages.
  2163.  * 
  2164.  * Sun Microsystems, Inc.
  2165.  * 2550 Garcia Avenue
  2166.  * Mountain View, California  94043
  2167.  */
  2168.  
  2169. /*
  2170.  * Find out about remote users
  2171.  */
  2172.  
  2173. const MAXUSERS = 100;
  2174. const MAXUTLEN = 256;
  2175.  
  2176. struct utmp {
  2177.     string ut_line<MAXUTLEN>;
  2178.     string ut_name<MAXUTLEN>;
  2179.     string ut_host<MAXUTLEN>;
  2180.     int ut_time;
  2181. };
  2182.  
  2183.  
  2184. struct utmpidle {
  2185.     utmp ui_utmp;
  2186.     unsigned int ui_idle;
  2187. };
  2188.  
  2189. typedef utmp utmparr<MAXUSERS>;
  2190.  
  2191. typedef utmpidle utmpidlearr<MAXUSERS>;
  2192.  
  2193. program RUSERSPROG {
  2194.     /*
  2195.      * Includes idle information
  2196.      */
  2197.     version RUSERSVERS_IDLE {
  2198.         int
  2199.         RUSERSPROC_NUM(void) = 1;
  2200.  
  2201.         utmpidlearr
  2202.         RUSERSPROC_NAMES(void) = 2;
  2203.  
  2204.         utmpidlearr
  2205.         RUSERSPROC_ALLNAMES(void) = 3;
  2206.     } = 1;
  2207.  
  2208.     /*
  2209.      * Old version does not include idle information
  2210.      */
  2211.     version RUSERSVERS_ORIG {
  2212.         int
  2213.         RUSERSPROC_NUM(void) = 1;
  2214.  
  2215.         utmparr
  2216.         RUSERSPROC_NAMES(void) = 2;
  2217.  
  2218.         utmparr
  2219.         RUSERSPROC_ALLNAMES(void) = 3;
  2220.     } = 2;
  2221. } = 100002;
  2222.     
  2223. Funky_Stuff
  2224. len=`wc -c < rnusers.x`
  2225. if [ $len !=     2151 ] ; then
  2226.   echo error: rnusers.x was $len bytes long, should have been     2151
  2227. fi
  2228. echo x - rquota.x
  2229. cat > rquota.x <<'Funky_Stuff'
  2230. /* @(#)rquota.x    1.2 87/11/12 3.9 RPCSRC */
  2231. /* @(#)rquota.x 1.2 87/09/20 Copyr 1987 Sun Micro */
  2232.  
  2233. /*
  2234.  * Remote quota protocol
  2235.  * Requires unix authentication
  2236.  */
  2237.  
  2238. const RQ_PATHLEN = 1024;
  2239.  
  2240. struct getquota_args {
  2241.     string gqa_pathp<RQ_PATHLEN>;      /* path to filesystem of interest */
  2242.     int gqa_uid;                /* inquire about quota for uid */
  2243. };
  2244.  
  2245. /*
  2246.  * remote quota structure
  2247.  */
  2248. struct rquota {
  2249.     int rq_bsize;            /* block size for block counts */
  2250.     bool rq_active;          /* indicates whether quota is active */
  2251.     unsigned int rq_bhardlimit;    /* absolute limit on disk blks alloc */
  2252.     unsigned int rq_bsoftlimit;    /* preferred limit on disk blks */
  2253.     unsigned int rq_curblocks;    /* current block count */
  2254.     unsigned int rq_fhardlimit;    /* absolute limit on allocated files */
  2255.     unsigned int rq_fsoftlimit;    /* preferred file limit */
  2256.     unsigned int rq_curfiles;    /* current # allocated files */
  2257.     unsigned int rq_btimeleft;    /* time left for excessive disk use */
  2258.     unsigned int rq_ftimeleft;    /* time left for excessive files */
  2259. };    
  2260.  
  2261. enum gqr_status {
  2262.     Q_OK = 1,        /* quota returned */
  2263.     Q_NOQUOTA = 2,      /* noquota for uid */
  2264.     Q_EPERM = 3        /* no permission to access quota */
  2265. };
  2266.  
  2267. union getquota_rslt switch (gqr_status status) {
  2268. case Q_OK:
  2269.     rquota gqr_rquota;    /* valid if status == Q_OK */
  2270. case Q_NOQUOTA:
  2271.     void;
  2272. case Q_EPERM:
  2273.     void;
  2274. };
  2275.  
  2276. program RQUOTAPROG {
  2277.     version RQUOTAVERS {
  2278.         /*
  2279.          * Get all quotas
  2280.          */
  2281.         getquota_rslt
  2282.         RQUOTAPROC_GETQUOTA(getquota_args) = 1;
  2283.  
  2284.         /*
  2285.           * Get active quotas only
  2286.          */
  2287.         getquota_rslt
  2288.         RQUOTAPROC_GETACTIVEQUOTA(getquota_args) = 2;
  2289.     } = 1;
  2290. } = 11;
  2291. Funky_Stuff
  2292. len=`wc -c < rquota.x`
  2293. if [ $len !=     1565 ] ; then
  2294.   echo error: rquota.x was $len bytes long, should have been     1565
  2295. fi
  2296. echo x - rstat.x
  2297. cd ..
  2298. echo more files to follow
  2299. exit
  2300.